package boundary;

import controler.ConnectionManager;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Vector;
import controler.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class InserirPacotesServlet
 */
@WebServlet("/CadastrarServlet")
public class CadastrarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public CadastrarServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String usuario=request.getParameter("usuario");
		String senha=request.getParameter("senha");
		String nome=request.getParameter("nome");
		String email=request.getParameter("email");
		String endereco=request.getParameter("endereco");
		String cpf=request.getParameter("cpf");
		String rg=request.getParameter("rg");
		Integer telefone=Integer.parseInt(request.getParameter("telefone"));
		if(DataManager.atualizarDados(usuario, senha, nome, email, endereco, cpf, rg, telefone))
			response.sendRedirect("./index.jsp?cd=sc");
		else
			response.getWriter().println("Erro na hora de inserir dados no cadastro");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
